package com.liang.lingdong.controller;

import com.liang.lingdong.common.BaseResponse;
import com.liang.lingdong.common.ErrorCode;
import com.liang.lingdong.common.ResultUtils;
import com.liang.lingdong.exception.BusinessException;
import com.liang.lingdong.model.sign.dto.SignUpDto;
import com.liang.lingdong.service.SignService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sign")
public class SignController {


    @Resource
    private SignService signService;


    /**
     * 用户报名比赛
     */
    @PostMapping("/signUp")
    public BaseResponse<Boolean> signUp(@RequestBody SignUpDto signUpDto) {
        if (signUpDto == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean flag = signService.signUp(signUpDto);
        return ResultUtils.success(flag);
    }

    /**
     * 用户取消报名
     */
    @PostMapping("/cancelSignUp")
    public BaseResponse<Boolean> cancelSignUp(@RequestBody SignUpDto signUpDto) {
        if (signUpDto == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean flag = signService.cancelSignUp(signUpDto);
        return ResultUtils.success(flag);
    }


    /**
     * 获取用户报名id
     */
    @GetMapping("/getSignInfo")
    public BaseResponse<Long> getSignInfo(Long examId) {
        if (examId == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        Long sign = signService.getSignInfo(examId);
        return ResultUtils.success(sign);
    }

}
